package com.aaa.controller.sds;

import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.sds.QuestionSds;
import com.aaa.entity.Result;
import com.aaa.service.sds.QuestionSdsService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 问题表(TblQuestionSds)表控制层
 *
 * @author makejava
 * @since 2022-08-30 10:35:12
 */
@RestController
@RequestMapping("/questionSds")
public class QuestionSdsController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private QuestionSdsService questionSdsService;

    /**
     * 查询所有
     *
     * @param pageSortEntity
     * @param questionSds
     * @return
     */
    @RequestMapping("/queryAllSdsPage.do")
    public Result queryAllSdsPage(PageSortEntity pageSortEntity, QuestionSds questionSds) {
        Page page = questionSdsService.queryQuestionSdsPage(pageSortEntity, questionSds);
        return success(page.getResult(), page.getTotal());
    }


    /**
     * @param
     * @return
     * @create by: 张恒
     * @description: 添加
     * @create time: 2022/8/31 9:11
     */
    @RequestMapping("saveQuestion.do")
    public Result saveQuestion(QuestionSds questionSds) {
        boolean insert = questionSdsService.insertQuestion(questionSds);
        if (insert) {
            return success();
        } else {
            return fail();
        }
    }


    /**
     * @param questionSds
     * @return
     * @create by: 张恒
     * @description: 修改
     * @create time: 2022/8/31 9:31
     */
    @RequestMapping("updateQuestion.do")
    public Result updateQuestion(QuestionSds questionSds) {
        boolean b = questionSdsService.updateQuestion(questionSds);
        if (b) {
            return success();
        } else {
            return fail();
        }
    }


    /**
     * @param
     * @return
     * @create by: 张恒
     * @description: 删除单个
     * @create time: 2022/8/31 9:20
     */

    @RequestMapping("deleteQuestionById.do")
    public Result deleteQuestionById(Integer[] id) {
        boolean b = questionSdsService.deleteQuestionById(id);
        if (b) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * @param questionSds
     * @return
     * @create by: 张恒
     * @description: 题目唯一性效验
     * @create time: 2022/8/31 17:27
     */
    @GetMapping("repetitionName.do")
    public Result repetitionName(QuestionSds questionSds) {
        boolean b = questionSdsService.repetitionName(questionSds);
        if (b) {
            return success("问题可用");
        } else {
            return fail("问题重复或为空,不可用");
        }
    }
}

